Skip to content

Conversation

@lufre1
Copy link
Contributor

@lufre1 lufre1 commented Dec 5, 2024

@constantinpape

I detected following issue with the current logic: after querying a vesicle pool and then querying a new vesicle pool, you cannot go back to the first one and edit it, as it will be overridden.

@lufre1 lufre1 linked an issue Dec 5, 2024 that may be closed by this pull request
Copy link
Contributor

@constantinpape constantinpape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for the pool assignments could be simplified a lot:

  • First find all the vesicles that are in any pool. From previous queries, if any, and the current query.
    • That is easy: get the ids matching the current query (currently valid_vesicle_ids), and combine it with ids from past queries (if any), which you have access to via the layer properties (if it exists).
    • If the pool name of the current query is already in the past pool names, then you over-write the ids for that poolname.
  • After this you don't need to introduce any special cases, just filter out the vesicle ids not in any pool, construct the properties and over-write the layer data and properties. (Or add a new layer with the properties if this is the first query)

props=props,
)
self._add_table(coords, radii, props, name="Vesicles")
self._add_table(coords, radii, props, name="Vesicles Morphology")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper spelling is "Vesicle Morphology".

pool_id = len(np.unique(layer.properties["pool"])) + 1
# compute vesicles with new pool_id and properties
for vesicle_id in valid_vesicle_ids:
new_layer_data[segmentation == vesicle_id] = pool_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few problems here:

  • You set the value in the layer to the pool_id. Instead we should keep the vesicle ids intact, but just filter out the vesicles that are not part of any pool.
  • The whole pool assignment and property logic could be simplified a lot, see the general comment for how.
  • The way you do this is in general inefficient. Instead of solving this with a loop you can for example do
filtered_vesicle_mask = ~np.isin(segmentation, valid_vesicle_ids)
new_layer_data[filtered_vesicle_mask] = 0

@constantinpape
Copy link
Contributor

I have simplified the implementation of the vesicle pool widget. It does not work 100% yet, but it should be easy to finish now. I will merge it despite the widget not 100% working, as I have fixed many other issues in the plugins and did quite some refactoring.

@constantinpape constantinpape merged commit efdee13 into main Dec 5, 2024
1 check passed
@constantinpape constantinpape deleted the 68-create-a-widget-for-vesicle-pool-assignments branch December 5, 2024 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a widget for vesicle pool assignments

3 participants